package com.znyj.cloud.device.util;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by gaoliwei02 on 2017/11/23.
 */
public class ExceptionUtil {
    protected static Map<String, Integer> autoCloseMap = new ConcurrentHashMap<>();
    protected static Map<String, Integer> packetLossMap = new ConcurrentHashMap<>();

    public static int addAutoCloseMap(String deviceId) {
        //不存在则添加并置1
        if (!autoCloseMap.containsKey(deviceId)) {
            autoCloseMap.put(deviceId, 1);
            return 1;
        } else {
            int temp = autoCloseMap.get(deviceId) + 1;
            autoCloseMap.put(deviceId, temp);
            return temp;
        }
    }

    public static void romoveAutoCloseMap(String deviceId) {
        if (autoCloseMap.containsKey(deviceId)) {
            autoCloseMap.remove(deviceId);
        }
    }

    public static int addPacketLossMap(String deviceId) {
        //不存在则添加并置1
        if (!packetLossMap.containsKey(deviceId)) {
            packetLossMap.put(deviceId, 1);
            return 1;
        } else {
            int temp = packetLossMap.get(deviceId) + 1;
            packetLossMap.put(deviceId, temp);
            return temp;
        }
    }

    public static void romovePacketLossMap(String deviceId) {
        if (packetLossMap.containsKey(deviceId)) {
            packetLossMap.remove(deviceId);
        }
    }
}
